import Vue from 'vue'
import Vuex from 'vuex'
import { getAdminInfo } from '../api/index'

Vue.use(Vuex)
const state = {
  adminInfo: {
    avatar: '17cb7269c90100903.jpg',
    admin: '管理员',
    city: '邵阳',
    create_time: '2021-10-21 16:54',
    id: '107956',
    user_name: '小姐姐'
  }
}

const mutations = {
  saveAdminInfo(state, adminInfo) {
    state.adminInfo = adminInfo
  }
}
const actions = {
  async getAdminData({ commit }) {
    try {
      const { data: res } = await getAdminInfo()
      if (res.status === 1) {
        commit('saveAdminInfo', res.data)
      } else {
        throw new Error(res.type)
      }
    } catch (error) {
      console.log(error)
    }
  }
}
const modules = {}

export default new Vuex.Store({
  state,
  mutations,
  actions,
  modules
})
